home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / mktil16a.zip / HEADERS.ZIP / GRAPHICS.H < prev    next >
C/C++ Source or Header  |  1994-09-19  |  13KB  |  750 lines

  1. #define SET 1
  2. #define NORMAL 1
  3. #define MASK 2
  4. #define ERASE 3
  5.  
  6. #ifndef byte
  7.  #define byte unsigned char
  8.  #define word unsigned int
  9.  #define d_word unsigned long
  10. #endif
  11.  
  12. #define FILL _GFILLINTERIOR
  13. #define BORDER _GBORDER
  14.  
  15. #ifndef byte
  16.  #define byte unsigned char
  17. #endif
  18.  
  19. #ifndef word
  20.  #define word unsigned int
  21. #endif
  22.  
  23. #define CLIP 0
  24. #define OUT_CLIP 1
  25. #define NO_CLIP 2
  26.  
  27. #define INVERSE 0
  28.  
  29. #define FONTS 128
  30. #define FONT_SIZE 8
  31.  
  32. #define SCREEN (byte huge *)0xA0000000
  33.  
  34. byte huge *screen;
  35.  
  36. word cos_table[256], sin_table[256], cos_table2[256], sin_table2[256];
  37.  
  38. /****************************************************************************/
  39. /****************************************************************************/
  40. /****************************************************************************/
  41.  
  42. void screen_set(word value, int c, size_t count)
  43. {
  44.  if (value>63999) return;
  45.  memset(screen+value,c,count);
  46. }
  47.  
  48. /****************************************************************************/
  49. /****************************************************************************/
  50. /****************************************************************************/
  51.  
  52. /****************************************************************************/
  53. /****************************************************************************/
  54. /****************************************************************************/
  55.  
  56. void put_image(int x, int y, byte huge *image,
  57.           word width, word height, word option)
  58. {
  59.  word value=(word)(y*320+x),
  60.       tileseg=FP_SEG(image),
  61.       tileoff=FP_OFF(image),
  62.       scrnseg=FP_SEG(screen),
  63.       scrnoff=FP_OFF(screen);
  64.  
  65.  if (option==NORMAL)
  66.  {
  67.   _asm
  68.   {
  69.    push    ds
  70.  
  71.    mov     ax,[tileseg]
  72.    mov     ds,ax
  73.    mov     si,[tileoff]
  74.  
  75.    mov     ax,[scrnseg]
  76.    mov     es,ax
  77.    mov     di,[scrnoff]
  78.    add     di,[value]
  79.  
  80.    mov     cx,[height]
  81.  
  82.    mov     bx,[x]
  83.    mov     dx,[y]
  84.  
  85.    start:
  86.    cmp     dx,199
  87.    jg      end
  88.  
  89.    push    cx
  90.  
  91.    cmp     dx,0
  92.    jl      start_end
  93.  
  94.    mov     cx,[width]
  95.  
  96.    mid:
  97.    cmp     bx,319
  98.    jg      mid_end
  99.    cmp     bx,0
  100.    jl      mid_end
  101.  
  102.    mov     al,[si]
  103.    mov     es:[di],al
  104.  
  105.    mid_end:
  106.    inc     bx
  107.    inc     di
  108.    inc     si
  109.    loop    mid
  110.  
  111.    sub     di,[width]
  112.  
  113.    start_end:
  114.    add     di,320
  115.    inc     dx
  116.    mov     bx,[x]
  117.    pop     cx
  118.  
  119.    loop    start
  120.  
  121.    end:
  122.    pop     ds
  123.   }
  124.  }
  125.  else if (option==MASK)
  126.  {
  127.   _asm
  128.   {
  129.    push   ds
  130.  
  131.    mov    ax,[tileseg]
  132.    mov    ds,ax
  133.    mov    si,[tileoff]
  134.  
  135.    mov    ax,[scrnseg]
  136.    mov    es,ax
  137.    mov    di,[scrnoff]
  138.    add    di,[value]
  139.  
  140.    mov    bx,[x]
  141.    mov    dx,[y]
  142.  
  143.    mov    cx,[height]
  144.  
  145.    star2:
  146.    cmp    dx,199
  147.    jg     mid6
  148.  
  149.    push   cx
  150.  
  151.    cmp    dx,0
  152.    jl     mid4
  153.  
  154.    mov    cx,[width]
  155.  
  156.    mid2:
  157.    cmp    bx,319
  158.    jg     mid3
  159.    cmp    bx,0
  160.    jl     mid3
  161.  
  162.    mov    al,ds:[si]
  163.    cmp    al,0
  164.    je     mid3
  165.    mov    es:[di],al
  166.  
  167.    mid3:
  168.    inc    di
  169.    inc    si
  170.    inc    bx
  171.  
  172.    loop   mid2
  173.  
  174.    sub    di,[width]
  175.  
  176.    mid4:
  177.    add    di,320
  178.    inc    dx
  179.    mov    bx,[x]
  180.  
  181.    pop    cx
  182.  
  183.    loop   star2
  184.  
  185.    mid6:
  186.    pop ds
  187.   }
  188.  }
  189.  else if (option==INVERSE)
  190.  {
  191.   _asm
  192.   {
  193.    push   ds
  194.  
  195.    mov    ax,[tileseg]
  196.    mov    ds,ax
  197.    mov    si,[tileoff]
  198.  
  199.    mov    ax,[scrnseg]
  200.    mov    es,ax
  201.    mov    di,[scrnoff]
  202.    add    di,[value]
  203.  
  204.    mov    bx,[x]
  205.    mov    dx,[y]
  206.  
  207.    mov    cx,[height]
  208.  
  209.    inv_star2:
  210.    cmp    dx,199
  211.    jg     inv_mid6
  212.  
  213.    push   cx
  214.  
  215.    cmp    dx,0
  216.    jl     inv_mid4
  217.  
  218.    mov    cx,[width]
  219.  
  220.    inv_mid2:
  221.    cmp    bx,319
  222.    jg     inv_mid3
  223.    cmp    bx,0
  224.    jl     inv_mid3
  225.  
  226.    mov    al,ds:[si]
  227.    mov    ah,al
  228.    shr    ah,1
  229.    shr    ah,1
  230.    shr    ah,1
  231.    shl    ah,1
  232.    shl    ah,1
  233.    shl    ah,1
  234.    add    ah,7
  235.    sub    ah,al
  236.    mov    al,ah
  237.    mov    es:[di],al
  238.  
  239.    inv_mid3:
  240.    inc    di
  241.    inc    si
  242.    inc    bx
  243.  
  244.    loop   inv_mid2
  245.  
  246.    sub    di,[width]
  247.  
  248.    inv_mid4:
  249.    add    di,320
  250.    inc    dx
  251.    mov    bx,[x]
  252.  
  253.    pop    cx
  254.  
  255.    loop   inv_star2
  256.  
  257.    inv_mid6:
  258.    pop ds
  259.   }
  260.  }
  261. }
  262.  
  263. /****************************************************************************/
  264. /****************************************************************************/
  265. /****************************************************************************/
  266.  
  267. void get_image(int x, int y, byte huge *image, word width, word height)
  268. {
  269.  word value=(word)(y*320+x),
  270.       tileseg=FP_SEG(image),
  271.       tileoff=FP_OFF(image),
  272.       scrnseg=FP_SEG(screen),
  273.       scrnoff=FP_OFF(screen);
  274.  
  275.  _asm
  276.   {
  277.    push    ds
  278.  
  279.    mov     ax,[tileseg]
  280.    mov     ds,ax
  281.    mov     si,[tileoff]
  282.  
  283.    mov     ax,[scrnseg]
  284.    mov     es,ax
  285.    mov     di,[scrnoff]
  286.    add     di,[value]
  287.  
  288.    mov     cx,[height]
  289.  
  290.    mov     bx,[x]
  291.    mov     dx,[y]
  292.  
  293.    start:
  294.    cmp     dx,199
  295.    jg      end
  296.  
  297.    push    cx
  298.  
  299.    cmp     dx,0
  300.    jl      start_end
  301.  
  302.    mov     cx,[width]
  303.  
  304.    mid:
  305.    cmp     bx,319
  306.    jg      mid_end
  307.    cmp     bx,0
  308.    jl      mid_end
  309.  
  310.    mov     al,es:[di]
  311.    mov     [si],al
  312.  
  313.    mid_end:
  314.    inc     bx
  315.    inc     di
  316.    inc     si
  317.    loop    mid
  318.  
  319.    sub     di,[width]
  320.  
  321.    start_end:
  322.    add     di,320
  323.    inc     dx
  324.    mov     bx,[x]
  325.    pop     cx
  326.  
  327.    loop    start
  328.  
  329.    end:
  330.    pop     ds
  331.   }
  332. }
  333.  
  334. /****************************************************************************/
  335. /****************************************************************************/
  336. /****************************************************************************/
  337.  
  338. void put_rotated(int scrn_x, int scrn_y, byte huge *image, byte option,
  339.          byte angle,
  340.          word x_left, word y_top, word x_right, word y_bottom)
  341. {
  342.  word right_x=(word)(cos_table[angle]);
  343.  word right_y=(word)(sin_table[angle]);
  344.  word down_x=(word)(cos_table2[angle]);
  345.  word down_y=(word)(sin_table2[angle]);
  346.  
  347.  word x=(8<<8)-(right_x<<3)-(down_x<<3);
  348.  word y=(8<<8)+(right_y<<3)+(down_y<<3);
  349.  word ox=x, oy=y;
  350.  
  351.  word scrn_seg=FP_SEG(screen);
  352.  word scrn_off=(scrn_y<<8)+(scrn_y<<6)+scrn_x;
  353.  
  354.  word image_seg=FP_SEG(image);
  355.  word image_off=FP_OFF(image);
  356.  
  357.  word x_clip=scrn_x;
  358.  word old_x_clip=x_clip;
  359.  word y_clip=scrn_y;
  360.  
  361.  if (option==CLIP)
  362.  {
  363.   _asm
  364.   {
  365.    push  ds
  366.  
  367.    mov   ax,[image_seg]
  368.    mov   ds,ax
  369.  
  370.    mov   ax,[scrn_seg]
  371.    mov   es,ax
  372.    mov   di,[scrn_off]
  373.  
  374.    mov   ax,[x]
  375.    mov   dx,[y]
  376.  
  377.    mov   cx,16
  378.  
  379.    start:
  380.    mov   bx,[y_clip]
  381.    cmp   bx,[y_bottom]
  382.    jl    start_mid
  383.    jmp   end
  384.  
  385.    start_mid:
  386.    push  cx
  387.  
  388.    cmp   bx,[y_top]
  389.    jle   startend
  390.  
  391.    mov   cx,16
  392.  
  393.    mid:
  394.    cmp   ah,0
  395.    jl    midend
  396.    cmp   ah,15
  397.    jg    midend
  398.    cmp   dh,0
  399.    jl    midend
  400.    cmp   dh,15
  401.    jg    midend
  402.  
  403.    mov   bx,[x_clip]
  404.    cmp   bx,[x_left]
  405.    jle   midend
  406.    cmp   bx,[x_right]
  407.    jge   midend
  408.  
  409.    mov   si,[image_off]
  410.    mov   bl,dh
  411.    shl   bl,1
  412.    shl   bl,1
  413.    shl   bl,1
  414.    shl   bl,1
  415.    add   bl,ah
  416.    and   bh,0x00
  417.    add   si,bx
  418.  
  419.    mov   bl,[si]
  420.    dec   bl
  421.    dec   bl
  422.    jz    nodraw
  423.    inc   bl
  424.    inc   bl
  425.  
  426.    mov   es:[di],bl
  427.  
  428.    midend:
  429.    nodraw:
  430.  
  431.    add   ax,[right_x]
  432.    sub   dx,[right_y]
  433.    inc   di
  434.    inc   [x_clip]
  435.  
  436.    loop mid
  437.  
  438.    sub   di,16
  439.  
  440.    startend:
  441.    add   di,320
  442.    inc   [y_clip]
  443.    mov   ax,[old_x_clip]
  444.    mov   [x_clip],ax
  445.  
  446.    mov   ax,[ox]
  447.    mov   dx,[oy]
  448.    add   ax,[down_x]
  449.    sub   dx,[down_y]
  450.    mov   [ox],ax
  451.    mov   [oy],dx
  452.  
  453.    pop   cx
  454.  
  455.    dec   cx
  456.    jz    end
  457.    jmp   start
  458.  
  459.    end:
  460.    pop   ds
  461.   }
  462.  }
  463.  else if (option==OUT_CLIP)
  464.  {
  465.   _asm
  466.   {
  467.    push  ds
  468.  
  469.    mov   ax,[image_seg]
  470.    mov   ds,ax
  471.  
  472.    mov   ax,[scrn_seg]
  473.    mov   es,ax
  474.    mov   di,[scrn_off]
  475.  
  476.    mov   ax,[x]
  477.    mov   dx,[y]
  478.  
  479.    mov   cx,16
  480.  
  481.    start2:
  482.    push  cx
  483.  
  484.    mov   cx,16
  485.  
  486.    mid2:
  487.    cmp   ah,0
  488.    jl    midend2
  489.    cmp   ah,15
  490.    jg    midend2
  491.    cmp   dh,0
  492.    jl    midend2
  493.    cmp   dh,15
  494.    jg    midend2
  495.  
  496.    mov   bx,[y_clip]
  497.    cmp   bx,[y_top]
  498.    jl    mid3
  499.    cmp   bx,[y_bottom]
  500.    jg    mid3
  501.  
  502.    mov   bx,[x_clip]
  503.    cmp   bx,[x_left]
  504.    jl    mid3
  505.    cmp   bx,[x_right]
  506.    jle    midend2
  507.  
  508.    mid3:
  509.    mov   si,[image_off]
  510.    mov   bl,dh
  511.    shl   bl,1
  512.    shl   bl,1
  513.    shl   bl,1
  514.    shl   bl,1
  515.    add   bl,ah
  516.    and   bh,0x00
  517.    add   si,bx
  518.  
  519.    mov   bl,[si]
  520.    dec   bl
  521.    dec   bl
  522.    jz    midend2
  523.    inc   bl
  524.    inc   bl
  525.    mov   es:[di],bl
  526.  
  527.    midend2:
  528.    sub   ax,[right_x]
  529.    add   dx,[right_y]
  530.    inc   di
  531.    inc   [x_clip]
  532.  
  533.    loop mid2
  534.  
  535.    sub   di,16
  536.  
  537.    startend2:
  538.    add   di,320
  539.    inc   [y_clip]
  540.    mov   ax,[old_x_clip]
  541.    mov   [x_clip],ax
  542.  
  543.    mov   ax,[ox]
  544.    mov   dx,[oy]
  545.    sub   ax,[down_x]
  546.    add   dx,[down_y]
  547.    mov   [ox],ax
  548.    mov   [oy],dx
  549.  
  550.    pop   cx
  551.  
  552.    dec   cx
  553.    jz    end2
  554.    jmp   start2
  555.  
  556.    end2:
  557.    pop   ds
  558.   }
  559.  }
  560.  else if (option==NO_CLIP)
  561.  {
  562.   _asm
  563.   {
  564.    push ds
  565.  
  566.    mov  ax,[image_seg]
  567.    mov  ds,ax
  568.  
  569.    mov  ax,[scrn_seg]
  570.    mov  es,ax
  571.    mov  di,[scrn_off]
  572.  
  573.    mov  ax,[x]
  574.    mov  dx,[y]
  575.  
  576.    mov  cx,16
  577.  
  578.    start_no_clip:
  579.    push  cx
  580.  
  581.    mov   cx,16
  582.  
  583.    mid_no_clip1:
  584.    cmp   ah,0
  585.    jl    midend_no_clip
  586.    cmp   ah,15
  587.    jg    midend_no_clip
  588.    cmp   dh,0
  589.    jl    midend_no_clip
  590.    cmp   dh,15
  591.    jg    midend_no_clip
  592.  
  593.    mov   si,[image_off]
  594.    mov   bl,dh
  595.    shl   bl,1
  596.    shl   bl,1
  597.    shl   bl,1
  598.    shl   bl,1
  599.    add   bl,ah
  600.    and   bh,0x00
  601.    add   si,bx
  602.  
  603.    mov   bl,[si]
  604.    dec   bl
  605.    dec   bl
  606.    jz    midend_no_clip
  607.    inc   bl
  608.    inc   bl
  609.    mov   es:[di],bl
  610.  
  611.    midend_no_clip:
  612.    sub   ax,[right_x]
  613.    add   dx,[right_y]
  614.    inc   di
  615.  
  616.    loop mid_no_clip1
  617.  
  618.    add   di,304
  619.  
  620.    mov   ax,[ox]
  621.    mov   dx,[oy]
  622.    sub   ax,[down_x]
  623.    add   dx,[down_y]
  624.    mov   [ox],ax
  625.    mov   [oy],dx
  626.  
  627.    pop   cx
  628.  
  629.    dec   cx
  630.    jz    end_no_clip
  631.    jmp   start_no_clip
  632.  
  633.    end_no_clip:
  634.    pop  ds
  635.   }
  636.  }
  637. }
  638.  
  639. /****************************************************************************/
  640. /****************************************************************************/
  641. /****************************************************************************/
  642.  
  643. void put_compressed(int x, int y, byte huge *image)
  644. {
  645.  word scrn_seg=FP_SEG(screen),
  646.       scrn_off=FP_OFF(screen)+(y<<8)+(y<<6)+x,
  647.       image_seg=FP_SEG(image),
  648.       image_off=FP_OFF(image);
  649.  
  650.  _asm
  651.  {
  652.   push  ds
  653.  
  654.   mov   ax,[image_seg]
  655.   mov   ds,ax
  656.   mov   si,[image_off]
  657.  
  658.   mov   ax,[scrn_seg]
  659.   mov   es,ax
  660.   mov   di,[scrn_off]
  661.  
  662.   start:
  663.   mov   cx,[si]
  664.   cmp   cl,0
  665.   je    end
  666.  
  667.   mov   bl,ch
  668.   and   ch,0x00
  669.  
  670.   draw:
  671.   mov   es:[di],bl
  672.   inc   di
  673.   dec   bh
  674.   jz    update
  675.   loop  draw
  676.   inc   si
  677.   inc   si
  678.   jmp   start
  679.  
  680.   update:
  681.   add   di,304
  682.   mov   bh,16
  683.   loop  draw
  684.   inc   si
  685.   inc   si
  686.   jmp   start
  687.  
  688.   end:
  689.   pop   ds
  690.  }
  691. }
  692.  
  693. /****************************************************************************/
  694. /****************************************************************************/
  695. /****************************************************************************/
  696.  
  697. void box(byte option, int x1, int y1, int x2, int y2, byte color)
  698. {
  699.  int a, b;
  700.  word width=x2-x1+1, height=y2-y1+1;
  701.  
  702.  if (option==BORDER)
  703.  {
  704.   screen_set(y1*320+x1,color,width);
  705.   for (a=y1+1;a<y2;a++)
  706.   {
  707.    screen_set(a*320+x1,color,1);
  708.    screen_set(a*320+x2,color,1);
  709.   }
  710.   screen_set(y2*320+x1,color,width);
  711.  }
  712.  else if (option==FILL)
  713.  {
  714.   a=y1;
  715.   do
  716.   {
  717.    screen_set(a*320+x1,color,width);
  718.   } while (a++<=y2);
  719.  }
  720. }
  721.  
  722. /****************************************************************************/
  723. /****************************************************************************/
  724. /****************************************************************************/
  725.  
  726. byte allocate_screen(void)
  727. {
  728.  screen=(byte huge *)halloc((long)64000,1);
  729.  if (screen==NULL)
  730.  {
  731.   printf("error allocating screen buffer\n");
  732.   return(FAILURE);
  733.  }
  734.  return(SUCCESS);
  735. }
  736.  
  737. /****************************************************************************/
  738. /****************************************************************************/
  739. /****************************************************************************/
  740.  
  741. void free_screen(void)
  742. {
  743.  if (screen!=NULL) hfree(screen);
  744. }
  745.  
  746.  
  747. /****************************************************************************/
  748. /****************************************************************************/
  749. /****************************************************************************/
  750.